package com.bl.student.manager.controller.withdrawals;

import com.bl.student.common.ApiResponseBody;
import com.bl.student.common.enums.SearchType;
import com.bl.student.common.utils.UUIDUtils;
import com.bl.student.manager.controller.BaseController;
import com.bl.student.service.biz.withdrawals.WithdrawalsService;
import com.bl.student.service.vo.DelBody;
import com.bl.student.service.vo.DelListBody;
import com.bl.student.service.vo.withdrawals.WithdrawalsListVo;
import com.bl.student.service.vo.withdrawals.WithdrawalsAddVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * Created by liangweikang on 18/12/26.
 */
@RestController
@Log4j2
@RequestMapping(value = {"/student/manager/withdraws"})
@Api(value = "提现相关api", description = "提现相关api")
public class WithdrawalsController extends BaseController{

    @Autowired
    WithdrawalsService withdrawalsService;

    @ApiOperation(value = "提现列表", notes = "提现列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "搜索类型", required = true, paramType = "query", dataType = "String", defaultValue = "ALL"),
            @ApiImplicitParam(name = "param", value = "参数", required = true, paramType = "query", dataType = "String", defaultValue = "1"),
            @ApiImplicitParam(name = "page", value = "页数", required = true, paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "size", value = "每页大小", required = true, paramType = "query", dataType = "int", defaultValue = "10")})
    @GetMapping(value = {"/get_list"})
    public ApiResponseBody<WithdrawalsListVo> getList(
            @RequestParam(value = "type", required = true, defaultValue = "ALL") String type,
            @RequestParam(value = "param", required = true, defaultValue = "") String param,
            @RequestParam(value = "page", required = true, defaultValue = "1") int page,
            @RequestParam(value = "size", required = true, defaultValue = "10") int size,
            HttpServletRequest request) {

        Pageable pageable = new PageRequest(page - 1, size);

        WithdrawalsListVo withdrawalsListVo = withdrawalsService.getList(param, type, pageable);

        return ApiResponseBody.createSuccessBody(withdrawalsListVo);
    }

//    @ApiOperation(value = "提现列表时间", notes = "提现列表时间")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "startTime", value = "开始时间", required = true, paramType = "query", dataType = "String", defaultValue = "0"),
//            @ApiImplicitParam(name = "endTime", value = "结束时间", required = true, paramType = "query", dataType = "String", defaultValue = "0"),
//            @ApiImplicitParam(name = "page", value = "页数", required = true, paramType = "query", dataType = "int", defaultValue = "1"),
//            @ApiImplicitParam(name = "size", value = "每页大小", required = true, paramType = "query", dataType = "int", defaultValue = "10")})
//
//    @GetMapping(value = {"/get_list_by_time"})
//    public ApiResponseBody<WithdrawalsListVo> getListByTime(
//            @RequestParam(value = "startTime", required = true, defaultValue = "0") String startTime,
//            @RequestParam(value = "endTime", required = true, defaultValue = "0") String endTime,
//            @RequestParam(value = "page", required = true, defaultValue = "1") int page,
//            @RequestParam(value = "size", required = true, defaultValue = "10") int size,
//            HttpServletRequest request) {
//
////        Pageable pageable = new PageRequest(page - 1, size);
//        WithdrawalsListVo withdrawalsListVo = withdrawalsService.getListByTime(startTime, endTime);
//
//        return ApiResponseBody.createSuccessBody(withdrawalsListVo);
//    }

    @ApiOperation(value = "增加一条提现记录", notes = "增加提现")
    @ApiImplicitParams({})
    @PostMapping(value = {"/add"})
    public ApiResponseBody add(
            @Valid @RequestBody WithdrawalsAddVo body, BindingResult result,
            HttpServletRequest request) {

        ApiResponseBody validResult = validParams(result);
        if (validResult != null) {
            return validResult;
        }
        withdrawalsService.add(body);

        return ApiResponseBody.createSuccessBody(null);
    }
}
